<!doctype html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎登录后台管理中心</title>
    <link rel="stylesheet" href="${(request.contextPath)!}/assets/css/login/login.css">
    <link rel="icon" type="image/png" href="${(request.contextPath)!}/assets/favicon.png" />
    <link rel="shortcut icon" type="image/x-icon" href="${(request.contextPath)!}/assets/favicon.png" />
</head>
<body class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message">欢迎登录后台管理中心</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form" action="${(request.contextPath)!}/login" autocomplete="off">
        <input name="account" placeholder="用户名" type="text" lay-verify="required" lay-reqtext="请输入用户名"
               value="" class="layui-input" title="用户名">
        <hr class="hr15">
        <input name="password" lay-verify="required|pass" placeholder="密码" type="password" class="layui-input"
               value="">
        <hr class="hr15">
        <div style="display: flex;">
            <input type="text" id="code"
                   name="code"
                   placeholder="验证码"
                   maxlength="4"
                   class="layui-input"
                   style="margin-right: 10px;" lay-verify="required|number" lay-reqtext="请输入验证码"/>
            <div class="code_img" title="点击刷新验证码">
                <img id="captchaImg" style="height: 50px;border-radius: 5px 0 0 5px;"/>
            </div>
        </div>
        <hr class="hr15">
        <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
        <hr class="hr20">
    </form>
</div>
<script type="text/javascript" src="${request.contextPath}/assets/js/sha/sha256.js"></script>
<#include "/comm/module.ftl"/>
<script>
    $(function () {
        let frame = self.frameElement;
        console.log("login-start");
        if (frame) {
            window.top.location.reload();
        }
        setTimeout(function () {
            $("#captchaImg").attr("src", "captcha?time=" + Math.random() + new Date().getTime()).fadeIn();
        }, 100);
        $("#captchaImg").click(function () {
            $(this).attr("src", "captcha?time=" + Math.random() + new Date().getTime()).fadeIn();
        });
        layui.use('form', function () {
            var form = layui.form;
            //自定义验证规则
            form.verify({
                pass: [/(.+){6,12}$/, '密码必须6到12位']
            });
            //监听提交
            form.on('submit(login)', function (data) {
                // 打开一个加载层
                var loadIndex = layer.msg('登录中......', {
                    time: 0, // 90s 后自动关闭
                    icon: 16, shade: 0.5
                });
                data.field.password = sha256_digest(data.field.password);
                $.post(data.form.action, data.field, function (result) {
                    layer.close(loadIndex)
                    if (result.code === 1) {
                        window.location.href = "center";
                    } else {
                       layer.msg(result.msg);
                    }
                }, "json");
                return false;
            });
        });
    })
</script>
</body>
</html>